package myJs

import myJs.Utils._
import myJs.myPkg._
import shared.Implicits._
import myJs.myPkg.jquery._

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.Dynamic.{global => g}
import scala.concurrent.ExecutionContext.Implicits.global
import myJs.Implicits._

/**
 * Created by yz on 2019/4/15
 */
@JSExportTopLevel("MyTool")
object MyTool {

  var score: BigDecimal = _
  var result: String = _

  @JSExport("init")
  def init = {

  }

  @JSExport("pdfInfoVal")
  def pdfInfoVal = {
    val url = g.jsRoutes.controllers.UserController.getPdfInfo().url.toString
    MyFetch.get(url = s"${url}",
      headers = Map("Content-Type" -> "application/json")).map { any =>
      refreshPdfInfo(any.toJDJAn)
    }.timeoutDeal
  }

  def refreshPdfInfo(dict: JDJAn) = {
    List("title", "unit", "address", "reporter", "checker").foreach { k =>
      val extraDataJson = g.extraDataJson.toJDJAn
      if (extraDataJson.myGet(k) != "") {
        $("#exportForm input[name='" + k + "']").`val`(extraDataJson.myGet(k))
      } else {
        $("#exportForm input[name='" + k + "']").`val`(dict.myGet(k))
      }
    }
  }

  @JSExport("showExport")
  def showExport={
    val url = g.jsRoutes.controllers.ToolController.getServerTime().url.toString
    MyFetch.get(url = s"${url}",
      headers = Map("Content-Type" -> "application/json")).map{ any=>
      g.showExportVal(any.toJDJAn.myGet("time"))
    }.timeoutDeal
  }


}
